#include "../../mqserver/msgqueue.hpp"
#include <gtest/gtest.h>

MyRabbitMQ::MsgQueueManager::ptr hosts;

class VirtualHostTest : public testing::Environment
{
public:
    // 初始化
    virtual void SetUp() override
    {
        hosts = std::make_shared<MyRabbitMQ::MsgQueueManager>("./data.db");
    }

    virtual void TearDown() override
    {
        // 清理队列操作
        // msgQueues->clear();
        std::cout << "执行真正数据库清理操作" << std::endl;
    }
};
// 声明测试
//TEST(MsgQueueTest, insert_test)
//{
//    msgQueues->declareMsgQueue("queue-1", true, true, true, google::protobuf::Map<std::string, std::string>());
//    msgQueues->declareMsgQueue("queue-2", true, true, true, google::protobuf::Map<std::string, std::string>());
//    msgQueues->declareMsgQueue("queue-3", true, true, true, google::protobuf::Map<std::string, std::string>());
//    msgQueues->declareMsgQueue("queue-4", true, false, true, google::protobuf::Map<std::string, std::string>());
//    msgQueues->declareMsgQueue("queue-5", true, false, true, google::protobuf::Map<std::string, std::string>());
//    msgQueues->declareMsgQueue("queue-6", true, true, true, google::protobuf::Map<std::string, std::string>());
//    msgQueues->declareMsgQueue("queue-7", true, true, true, google::protobuf::Map<std::string, std::string>());
//}
//
//// 删除测试
//TEST(MsgQueueTest, delete_test)
//{
//    msgQueues->deleteMsgQueue("queue-2");
//    msgQueues->deleteMsgQueue("queue-3");
//}

// 获取指定与获取全部测试
TEST(VirtualHostTest, get_test)
{
    auto exp = hosts->getMsgQueue("queue-1");
    LOG(logLevel::DEBUG) << exp->m_name << std::endl;
    LOG(logLevel::DEBUG) << exp->m_isUnique << std::endl;
    LOG(logLevel::DEBUG) << exp->m_isDurable << std::endl;
    LOG(logLevel::DEBUG) << exp->m_isAutoDelete << std::endl;
    LOG(logLevel::DEBUG) << exp->getArgs() << std::endl;

    auto exps = hosts->getMsgQueueAll();

    for (auto &f : exps)
    {
        LOG(logLevel::DEBUG) << f.second->m_name << std::endl;
        LOG(logLevel::DEBUG) << f.second->m_isUnique << std::endl;
        LOG(logLevel::DEBUG) << f.second->m_isDurable << std::endl;
        LOG(logLevel::DEBUG) << f.second->m_isAutoDelete << std::endl;
        LOG(logLevel::DEBUG) << f.second->getArgs() << std::endl;
    }
}

//判断是否存在测试
 TEST(VirtualHostTest,exists_test)
{
     LOG(logLevel::DEBUG) << hosts->exists("queue-1") << std::endl;
     LOG(logLevel::DEBUG) << hosts->exists("queue-2") << std::endl;
     LOG(logLevel::DEBUG) << hosts->exists("queue-3") << std::endl;
 }

//获取管理数量测试
 TEST(VirtualHostTest,getSize_test)
{
     LOG(logLevel::DEBUG) << hosts->size() << std::endl;
 }

//持久化恢复历史数据测试



int main(int argc, char *argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new VirtualHostTest);
    int ret = RUN_ALL_TESTS();
    return 0;
}